package controller;

import java.io.PrintWriter;
import java.util.ArrayList;

import com.dncompute.marrow.Controller;

/**
 * 
 * This is an example of how you could override the preprocess method to 
 * require user authentication on a service 
 * 
 * Look at controller.Profile to see an example in use
 * 
 */
public abstract class AdvAuth extends Controller {
	
	private static final long serialVersionUID = 1L;
	
	protected boolean preprocess(ArrayList<String> path) {
		
		//Replace this check with a check to see if the user is logged in
		//against whatever authentication method you employ)
		if (req.getParameter("password").equals("1234") ) {
			
			//The user is not logged in, handle this
			try {
				PrintWriter out = res.getWriter();
				out.println("You must be logged in to access this service");
				out.close();
			} catch (Exception e) {}
			return true;
			
		} else {
			
			//The user is logged in, proceed as usual
			return false;
			
		}
		
	}
		
}
